package com.kindnesslibrary.network.upload;

import android.os.Handler;

import com.kindnesslibrary.network.HttpConfig;
import com.kindnesslibrary.network.HttpUtils;
import com.kindnesslibrary.network.callback.HttpCallBack;

import java.io.File;

/**
 * 上传文件线程
 */
public class SingleUploadFileThread extends SingUploadCallBack {

    private HttpCallBack httpCallBack;
    private HttpUtils httpUtils = HttpUtils.getInstance();

    public SingleUploadFileThread(File uploadFile, String url, String fileParam, Object content, Handler handler, HttpCallBack httpCallBack) {
        super(uploadFile, url, fileParam, content, handler);
        this.httpCallBack = httpCallBack;
    }

    @Override
    public void runing() {
        uploadFile();
    }

    /**
     * 上传文件
     */
    private void uploadFile() {
        if(httpCallBack != null){
            String result = httpUtils.singlePploadFile(getUploadFile(), getUrl(), getFileParam(), getContent());
            httpCallBack.onRequestOk(result);
        } else{
            sendMessage(HttpConfig.MSG_CANCEL, 0, null);
        }
    }
}
